/**
 * Software License, Version 1.0
 * 
 * Copyright 2003 The Trustees of Indiana University.  All rights reserved.
 * 
 *
 *Redistribution and use in source and binary forms, with or without 
 *modification, are permitted provided that the following conditions are met:
 *
 *1) All redistributions of source code must retain the above copyright notice,
 * the list of authors in the original source code, this list of conditions and
 * the disclaimer listed in this license;
 *2) All redistributions in binary form must reproduce the above copyright 
 * notice, this list of conditions and the disclaimer listed in this license in
 * the documentation and/or other materials provided with the distribution;
 *3) Any documentation included with all redistributions must include the 
 * following acknowledgement:
 *
 *"This product includes software developed by the Community Grids Lab. For 
 * further information contact the Community Grids Lab at 
 * http://communitygrids.iu.edu/."
 *
 * Alternatively, this acknowledgement may appear in the software itself, and 
 * wherever such third-party acknowledgments normally appear.
 * 
 *4) The name Indiana University or Community Grids Lab or NaradaBrokering, 
 * shall not be used to endorse or promote products derived from this software 
 * without prior written permission from Indiana University.  For written 
 * permission, please contact the Advanced Research and Technology Institute 
 * ("ARTI") at 351 West 10th Street, Indianapolis, Indiana 46202.
 *5) Products derived from this software may not be called NaradaBrokering, 
 * nor may Indiana University or Community Grids Lab or NaradaBrokering appear
 * in their name, without prior written permission of ARTI.
 * 
 *
 * Indiana University provides no reassurances that the source code provided 
 * does not infringe the patent or any other intellectual property rights of 
 * any other entity.  Indiana University disclaims any liability to any 
 * recipient for claims brought by any other entity based on infringement of 
 * intellectual property rights or otherwise.  
 *
 *LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH NO 
 *WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA UNIVERSITY GIVES
 *NO WARRANTIES AND MAKES NO REPRESENTATION THAT SOFTWARE IS FREE OF 
 *INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR OTHER PROPRIETARY RIGHTS. 
 *INDIANA UNIVERSITY MAKES NO WARRANTIES THAT SOFTWARE IS FREE FROM "BUGS", 
 *"VIRUSES", "TROJAN HORSES", "TRAP DOORS", "WORMS", OR OTHER HARMFUL CODE.  
 *LICENSEE ASSUMES THE ENTIRE RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR 
 *ASSOCIATED MATERIALS, AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION 
 *GENERATED USING SOFTWARE.
 */
/*
 * TopologyViewer
 */

package cgl.narada.topology.viewer;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

class helpWindowAdapter extends WindowAdapter {
    HelpFrame frame;
    public helpWindowAdapter(HelpFrame frame) {
	this.frame = frame;
    }
    public void windowClosing(WindowEvent we) {
	frame.setVisible(false);
    }  
}   

/**
 * Represents Help Window
 */
public class HelpFrame extends JFrame {

    private String type;
    private Dimension area;

    public HelpFrame(String s) {
	type = s;
	if (type.equals("about")) {
	    area = new Dimension(200, 200);
	} else {
	    area = new Dimension(650, 900);
	}
	JFrame.setDefaultLookAndFeelDecorated(true);
	
	HelpPanel helpPanel = new HelpPanel();
	helpPanel.setBackground(Color.LIGHT_GRAY);
	helpPanel.setPreferredSize(area);
	helpPanel.scrollRectToVisible(new Rectangle(0, 0, area.width,
							 area.height));

	JScrollPane scroller = new JScrollPane(helpPanel);
	if (type.equals("about")) {
	    scroller.setPreferredSize(new Dimension(200, 200));
	} else {
	    scroller.setPreferredSize(new Dimension(400, 600));
	}

	JPanel newContentPane = new JPanel();
	newContentPane.add(scroller, BorderLayout.CENTER);
	newContentPane.setOpaque(true);

	this.setContentPane(newContentPane);
	helpWindowAdapter adapter = new helpWindowAdapter(this);    	
	addWindowListener(adapter);    
	this.pack();
	this.setVisible(true);
    }

    public class HelpPanel extends JPanel {
	public void paintComponent(Graphics g) {
	    super.paintComponent(g);
	    g.setColor(Color.BLACK);
	    g.setFont(new Font("Arial", Font.PLAIN, 10));
	    if (type.equals("about")) {
		g.drawString("Topology Viewer", 20, 50);
		g.drawString("Version 0.5", 20, 70);
		g.drawString("Naradabrokering Project", 20, 90);
		g.drawString("Community Grid Labs", 20, 110);
		g.drawString("Pervasive Technologies", 20, 130);
		g.drawString("Indiana University", 20, 150);
		g.drawString("Bloomington, IN", 20, 170);
	    } else {
		g.drawString("Topology Viewer is a simple visualization tool developed specifically for NaradaBrokering project.", 20, 50);
		g.drawString("It enables to view and navigate throght the topology of broker nodes.", 20, 70);
		g.setFont(new Font("Arial", Font.BOLD, 15));
		g.drawString("COMPONENTS:", 20, 100);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("Node:", 20, 120);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Broker node with unique node address:", 
			     140, 120);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("Cluster:", 20, 140);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Group of broker nodes", 140, 140);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("Super Cluster:", 20, 160);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Group of clusters", 140, 160);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("Super Super Cluster:", 20, 180);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Group of super clusters", 140, 180);
		g.drawString("All above components are circular with different colors. Each component is marked by its ID at top.", 20, 200);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("Link:", 20, 220);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("link between two broker nodes.", 140, 220);
		g.drawString("Links between broker nodes exhibit different colors depending upon the location of nodes", 20, 240);
		g.drawString("Link between nodes in same cluster - color1", 
			     20, 260);
		g.drawString("Link between nodes in different cluster but in same super cluster - color2", 20, 280);
		g.drawString("Link between nodes in different super clusters but in same super super clusters - color3", 20, 300);
		g.drawString("Link between nodes in different super super clusters - color4", 20, 320);
		g.drawString("There can be multiple links between two broker nodes.", 20, 340);
		g.drawString("A single line between two nodes represents one or more links existing between those nodes.", 20, 360);
		g.drawString("Nodes and links gets added or removed from the view dynamically as soon as the topology changes.", 20, 380);
		
		g.setFont(new Font("Arial", Font.BOLD, 15));
		g.drawString("USER ACTIONS:", 20, 410);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("FILE MENU:", 20, 430);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Save Option:", 20, 450);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Current topology view is saved as .png file in user selected local directory.", 20, 470);
		g.drawString("The view is of the instant when the save option is clicked.", 20, 480);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Print Option:", 20, 500);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Current topology view is directed for printing.",
			     20, 520);
		g.drawString("The view is of the instant when th print option is clicked.", 20, 530); 
		
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("NAVIGATION:", 20, 550);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Zoom In:", 20, 570);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Zooms in the image with respect to the center of the image (screen-center)", 20, 590);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Zoom Out:", 20, 610);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Zooms out the image with respect to the center of the image (screen-center)", 20, 630);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Resize:", 20, 650);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Resets the image to original position and size",
			     20, 670);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("INFORMATION:", 20, 690);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Node Information:", 20, 710);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Enables user to find information about any of the broker node when right clicked.", 20, 730);
		g.drawString("New frame displays information about the node and its connections when the node is right clicked.", 20, 740);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Link Information:", 20, 760);
		g.setFont(new Font("Arial", Font.PLAIN, 10));
		g.drawString("Enables user to find information about links between two nodes.", 20, 780);
		g.drawString("In this mode whenever one of the end nodes is right clicked, it appears in black color.", 20, 790);
		g.drawString("As soon as the other end node is right clicked, frame displaying information about all links between selected node appears.",
			     20, 800);
		g.setFont(new Font("Arial", Font.BOLD, 12));
		g.drawString("Note:", 20, 820);
		g.setFont(new Font("Arial", Font.PLAIN, 11));
		g.drawString("Node Information and Link Information are two different modes and in each mode, interpretation of a right click of mouse is different.", 20, 840);
	    }
	}
    }
};
	    
